package de.rts.ui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;

public class Util
{

  public static Component defineFont(Component c, Font f)
  {
    c.setFont(f);
    return c;
  }

  public static Color setHSBColor(int h, int s, int b)
  {
    return Color.getHSBColor((float) h / 360, (float) s / 100, (float) b / 100);
  }
  
  public static void drawThickLine(
    Graphics g, int x1, int y1, int x2, int y2, int thickness, Color c) {
    g.setColor(c);
    int dX = x2 - x1;
    int dY = y2 - y1;
    double lineLength = Math.sqrt(dX * dX + dY * dY);

    double scale = (double)(thickness) / (2 * lineLength);

    double ddx = -scale * (double)dY;
    double ddy = scale * (double)dX;
    ddx += (ddx > 0) ? 0.5 : -0.5;
    ddy += (ddy > 0) ? 0.5 : -0.5;
    int dx = (int)ddx;
    int dy = (int)ddy;

    int xPoints[] = new int[4];
    int yPoints[] = new int[4];

    xPoints[0] = x1 + dx; yPoints[0] = y1 + dy;
    xPoints[1] = x1 - dx; yPoints[1] = y1 - dy;
    xPoints[2] = x2 - dx; yPoints[2] = y2 - dy;
    xPoints[3] = x2 + dx; yPoints[3] = y2 + dy;

    g.fillPolygon(xPoints, yPoints, 4);
    }
}
